<template>
  <div class="container">
    <div class="head-top">
      <span>助记词</span>
      <img @click="$router.back()" src="static/img/return.png" alt />
    </div>
    <div class="remind">
      <div>
        <span class="dot">o</span>&nbsp;以下是钱包的助记词，务必抄写下来并导出至安全的地方存放。一旦丢失，将无法找回。
      </div>
    </div>

    <div class="body">
      <div v-for="(item,index) in mnemonicArr" :key="index">{{item}}</div>
    </div>
    <div class="btn" @click="newAccount">
       <img src="static/img/backups.png" alt />
      <span>我已备份</span>
    </div>
  </div>
</template>


<script>
import { Field, Checklist, Button } from "mint-ui";

import { Dialog, Toast } from "vant";

import { mainCoinList } from "../../../service/eth/config";
import { mapGetters, mapActions } from "vuex";
import accountUtils from "../../../service/eth/accountUtils";
import web3Utils from "../../../service/eth/web3Utils";
export default {
  components: {
    Field,
    Checklist,
    Button,
  },
  data() {
    return {
      account: this.$route.params.account,
      mnemonicArr: this.$route.params.account.mnemonic.split(" "),
    };
  },
  computed: {
    ...mapGetters([
      "wallet",
      "accountIndex",
      "currentAccount",
      "contactList",
      "messageList",
      "ethBaseNet",
      "infuraAK",
    ]),
    zs() {
      return this.pwd.length;
    },
  },
  methods: {
    ...mapActions([
      "setWallet",
      "setAccountIndex",
      "setContactList",
      "setWalletAccountByIndex",
      "setMessageList",
    ]),
    newAccount() {
      let _this = this;

      Dialog.confirm({
        title: "确定已完成备份？",
      })
        .then(() => {
          Toast.loading({
            duration: 0,
            forbidClick: true,
            message: "loading...",
          });

          setTimeout(() => {
            _this.wallet.push(_this.account);
            _this.setWallet(_this.wallet);

            let accountIndex = _this.wallet.length - 1;
            _this.setAccountIndex(accountIndex);

            let hasContact = false;
            if (!_this.contactList) {
              _this.contactList = [];
            }
            for (let z = 0; z < _this.contactList.length; z++) {
              if (_this.contactList.address == _this.account.address) {
                hasContact = true;
                break;
              }
            }

            if (!hasContact) {
              let contact = {
                name: _this.account.name,
                address: _this.account.address,
                phone: "",
                email: "",
                remark: "",
                date: _this
                  .formatDateTime(new Date().getTime())
                  .substring(0, 10),
              };
              _this.contactList.push(contact);
              _this.setContactList(_this.contactList);
            }
            Toast.clear();
            _this.$router.push({ name: "Index" });
          }, 200);
        })
        .catch(() => {
          // on cancel
        });
    },

    formatDateTime(inputTime) {
      var date = new Date(inputTime);
      var y = date.getFullYear();
      var m = date.getMonth() + 1;
      m = m < 10 ? "0" + m : m;
      var d = date.getDate();
      d = d < 10 ? "0" + d : d;
      var h = date.getHours();
      h = h < 10 ? "0" + h : h;
      var minute = date.getMinutes();
      var second = date.getSeconds();
      minute = minute < 10 ? "0" + minute : minute;
      second = second < 10 ? "0" + second : second;
      return y + "-" + m + "-" + d + " " + h + ":" + minute + ":" + second;
    },
  },
  async mounted() {},
};
</script>
<style scoped>
@import url("../../../assets/css/ethSaveMemonic.css");
</style>

